package demo2.demo2.config;

import javax.xml.ws.Endpoint;

import demo2.demo2.service.PeopleService;
import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import demo2.demo2.service.UserService;
/**
 * @ClassName:CxfConfig
 * @Description:cxf发布webservice配置
 */
@Configuration
//@ConditionalOnWebApplication
public class CxfConfig {

    @Autowired
    private Bus bus ;

    @Autowired
    UserService userService ;

    @Autowired
    PeopleService peopleService ;


    /**
     * 此方法作用是改变项目中服务名的前缀名，此处127.0.0.1或者localhost不能访问时，
     * 请使用ipconfig查看本机ip来访问
     * 此方法被注释后:wsdl访问地址为http://127.0.0.1:8080/services/user?wsdl
     * 去掉注释后：wsdl访问地址为：http://127.0.0.1:8080/soap/user?wsdl
     * @return
     */
    // 不能注册此类， 否者无法使用rest controller
//    @SuppressWarnings("all")
//    @Bean
//    public ServletRegistrationBean dispatcherServlet() {
//        return new ServletRegistrationBean (new CXFServlet(), "/services/*");
//    }

    /** JAX-WS
     * 站点服务
     * 配置CXF服务发布，默认服务是在host:port/services/发布地址
     * 访问地址 http://127.0.0.1:8080/myService/UserService?wsdl
     * **/
    @Bean
    public Endpoint endpoint_user() {
        EndpointImpl endpoint = new EndpointImpl(bus, userService);
        endpoint.publish("/UserService");   // 访问
        return (Endpoint)endpoint;
    }

    @Bean
    public Endpoint endpoint_people() {
        EndpointImpl endpoint = new EndpointImpl(bus, peopleService);
        endpoint.publish("/PeopleService");   // 访问
        return (Endpoint)endpoint;
    }

}